package com.yanqu.road.server.cmd.specialcookboy.specialcookboysign;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.specialcookboy.SpecialCookBoyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.specialcookboy.SpecialCookBoySignMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SPECIAL_COOK_BOY_SIGN,desc = "小当家特色服七日签到")
public class SpecialCookBoySignCmd extends AbstractCommand {

    private int activityId;
    private int conditionId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SpecialCookBoyProto.SpecialCookBoySevenDaySignReq req = SpecialCookBoyProto.SpecialCookBoySevenDaySignReq.parseFrom(packet.getBytes());
        activityId =req.getActivityId();
        conditionId = req.getConditionId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = SpecialCookBoySignMgr.simpleSign(player,activityId,conditionId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            SpecialCookBoyProto.SpecialCookBoySevenDaySignResp.Builder builder = SpecialCookBoyProto.SpecialCookBoySevenDaySignResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SPECIAL_COOK_BOY_SIGN,builder);
        }
    }
}
